

package ru.samgtu.wst.ui.swing;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import ru.samgtu.wst.model.ConversationID;
import ru.samgtu.wst.model.ConversationModel;


public class ConversationRenderer extends JLabel implements ListCellRenderer {

	private ConversationModel _conversationModel;

	/** Creates a new instance of ConversationRenderer */
	public ConversationRenderer(ConversationModel conversationModel) {
		_conversationModel = conversationModel;
	}

	public java.awt.Component getListCellRendererComponent(JList list,
			Object value, int index, boolean isSelected, boolean cellHasFocus) {
		// Get the selected index. (The index param isn't
		// always valid, so just use the value.)
		ConversationID id = (ConversationID) value;

		if (isSelected) {
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		} else {
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		}

		if (id == null) {
			setText("");
			return this;
		}
		if (_conversationModel == null) {
			setText(id.toString());
			return this;
		}
		StringBuffer text = new StringBuffer();
		text.append(id).append(" - ");
		text.append(_conversationModel.getRequestMethod(id)).append(" ");
		text.append(_conversationModel.getRequestUrl(id).getSHPP()).append(
				"    ");
		text.append(_conversationModel.getResponseStatus(id));
		setText(text.toString());

		return this;
	}

}
